#include <iostream>
#include <string>
#include <cstring>
#include <stack>
using namespace std;

typedef string newType;

typedef struct BTree
{
	newType data;
	struct BTree* lchild, * rchild;
}BTree;


void CreateBTree(BTree* &h) //创建
{
	h = new BTree;//申请空间
	cin >> h->data;
	if (h->data == "#") return;
	CreateBTree(h->lchild);
	CreateBTree(h->rchild);
}

void OutBTree(BTree* h) //左中右遍历
{
	if (h->data == "#") return;
	if (h->lchild->data == "#" && h->rchild->data == "#")
	{
		cout << h->data;
		return;
	}
	cout << '(';
	OutBTree(h->lchild);
	cout << h->data ;
	OutBTree(h->rchild);
	cout << ')';
}


int main()
{
	while (true)
	{
		BTree* h;
		h = new BTree;
		if (!(cin >> h->data)) break; //不输入直接退出
		CreateBTree(h->lchild);
		CreateBTree(h->rchild);
		OutBTree(h);
		cout << endl;
	}
	return 0;
}




//数据测试
//+ 13 # # * 5 # # 9 # #
//* + 13 # # 5 # # 9 # #